Skip to content

fix(slack): use event.ts as threadTs fallback for DMs#292

Open
chechunhsu wants to merge 1 commit intovercel:mainfrom
chechunhsu:fix/slack-dm-thread-ts
Open

fix(slack): use event.ts as threadTs fallback for DMs#292
chechunhsu wants to merge 1 commit intovercel:mainfrom
chechunhsu:fix/slack-dm-thread-ts

Conversation

@chechunhsu
Copy link

@chechunhsu chechunhsu commented Mar 24, 2026

Summary

Fixes #268

When handling DM (direct message) events, the Slack adapter set threadTs to an empty string when event.thread_ts was undefined:

// Before
const threadTs = isDM ? event.thread_ts || "" : event.thread_ts || event.ts;

This caused invalid_thread_ts errors from the Slack API when attempting to stream responses back to DMs via chatStream.

The fix uses event.ts as the fallback for all message types:

// After
const threadTs = event.thread_ts || event.ts;

This ensures the bot replies in a thread under the original DM message, matching the behavior for channel messages.

Behavioral Note

This changes how top-level DM messages interact with openDM() subscriptions:

  • Before: top-level DM threadId was slack:CHANNEL: (empty threadTs), which exactly matched openDM() subscription IDs → messages routed to onSubscribedMessage()
  • After: top-level DM threadId is slack:CHANNEL:event.ts → messages now route to onNewMention() instead of onSubscribedMessage()

Apps using openDM() and relying on exact subscription matching should be aware of this change. Messages are still delivered correctly — only the routing handler changes.

Test plan

  • Updated unit tests and integration tests to verify the new behavior
  • Verified the fix resolves the invalid_thread_ts error in a production deployment
  • Bot now correctly replies to DMs with streaming responses in a thread
  • pnpm validate passes cleanly

Fixes vercel#268

When handling DM messages, threadTs was set to empty string when
event.thread_ts was undefined. This caused invalid_thread_ts errors
from the Slack API when streaming responses. The fix uses event.ts
as fallback consistently for all message types.
@vercel
Copy link
Contributor

vercel bot commented Mar 24, 2026

@chechunhsu is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Test description claims "top-level DM messages use empty threadTs (matches openDM subscriptions)" but the test assertion expects a non-empty threadTs using event.ts, contradicting the description.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DMs broken: empty threadTs causes invalid_thread_ts and invalid_arguments

1 participant